import pickle, pprint


def writefile():
    f = open("./tmp/foo.txt", "w")
    f.write("Python 是一个非常好的语言。\n是的,的确非常好!!\n")
    f.close()


def readfile():
    f = open("./tmp/foo.txt", "r")
    # content = f.read()
    # content = f.readline() # 读取1行
    content = f.readlines()
    print(content)
    f.close()


def serialobject(data):
    out = open('data.pkl', "wb")

    if (isinstance(data, dict)):
        # Pickle dictionary using protocol 0.
        pickle.dump(data, out)
    elif (isinstance(data, list)):
        # Pickle the list using the highest protocol available.
        pickle.dump(data, out, -1)
    out.close()


def untiserialobject():
    pkl_file = open('data.pkl', "rb")
    data = pickle.load(pkl_file)
    pprint.pprint(data)
    pkl_file.close()


# writefile()

# readfile()
data1 = {'a': [1, 2.0, 3, 4+6j],
         'b': ('string', u'Unicode string'),
         'c': None}


# serialobject(data1)
untiserialobject()
